package com.ghh.dao;


import com.ghh.pojo.CheckItem;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckitemDao {

    //添加检查项
    @Insert("insert into t_checkitem values (null,#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})")
    void addCheckitem(CheckItem checkItem);

    //分页查询检查项
    @Select("<script>select * from t_checkitem <if test=\"value!=null and value!=''\">where code like '%${value}%' or name like '%${value}%'</if></script>")
    Page<CheckItem> findByCondition(@Param("value") String queryString);

    //根据id删除检查项
    @Delete("delete from t_checkitem where id = #{id}")
    void deleteCheckitem(int id);

    //根据id查找检查项
    @Select("select * from t_checkitem where id = #{id}")
    CheckItem findById(int id);

    //查询所有
    @Select("select * from t_checkitem")
    List<CheckItem> findAll();

    //修改检查项
    @Update("update t_checkitem set code=#{code},name=#{name},sex=#{sex},age=#{age},price=#{price},type=#{type},remark=#{remark},attention=#{attention} where id = #{id}")
    void updateCheckitem(CheckItem checkItem);

    //根据检查项ID查询是否与检查组关联
    @Select("select count(1) from t_checkgroup_checkitem where checkitem_id = #{id}")
    long findCountByCheckitem(int id);


    @Select("select * from t_checkitem where id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{id})")
    List<CheckItem> findAllCheckItem(Integer id);
}
